﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using cecbClasses;
using cecbData;
using cecbClasses.Data_Classes;
using cecbClasses.Data_Adapters.Project;



namespace CECB.Project
{
    /// <summary>
    /// Interaction logic for ProjectCatogry.xaml
    /// </summary>
    public partial class ProjectCatogry : Window
    {
        Func_Projects ObjProjFunc = new Func_Projects();
        Data_Categories objCat = new Data_Categories();
        public ProjectCatogry()
        {
            InitializeComponent();


            CatgoryAutocompleteTextBox.ItemsSource = ObjProjFunc.GetAllCatogries();
        }

        private void button_catgryInsert_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                // objCat.Cat_reference = comboBox_insertCatRef.Text;
                objCat.Cat_name = textBox_EntrNewCatNam.Text;
                ObjProjFunc.insertIntoCategories(objCat);
                MessageBox.Show("New Catogry Inserted Successfully!", "Project Catogry", MessageBoxButton.OK, MessageBoxImage.Information);
            }


            catch
            {

                MessageBox.Show("Project Refence Already Exited!!!!", "Project Catogry", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {

        }

        private void button_Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {


        }

        public void FillProjCatgries()
        {

            List<cecbData.Categories> ProjCatgryList = ObjProjFunc.GetAllCatref();
            //comboBox_insertCatRef.ItemsSource = ProjCatgryList;


        }
        private void CatgoryAutocompleteTextBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            objCat.Cat_name = CatgoryAutocompleteTextBox.Text;
            cecbData.Categories selectedPrj = ObjProjFunc.GetProjectBycatName(objCat);
            label_CatRef.Content = selectedPrj.cat_reference;


        }

        private void button_close_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void textBox_CatRef_TextChanged(object sender, TextChangedEventArgs e)
        {

        }



        private void button1_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void ButtonInsertPage_Click(object sender, RoutedEventArgs e)
        {
            wrapPanel_SearchDetails.Visibility = System.Windows.Visibility.Hidden;
            wrapPanel_UpdateCatName.Visibility = System.Windows.Visibility.Hidden;
            button_catUpdate.Visibility = System.Windows.Visibility.Hidden;
            button_catDelete.Visibility = System.Windows.Visibility.Hidden;

            wrapPanel_EnterNewCat.Visibility = System.Windows.Visibility.Visible;
            //wrapPanel_EnterCatRef.Visibility = System.Windows.Visibility.Visible;

            button_catgryInsert.Visibility = System.Windows.Visibility.Visible;


        }

        private void button_updtDel_Click(object sender, RoutedEventArgs e)
        {
            CatgoryAutocompleteTextBox.ItemsSource = ObjProjFunc.GetAllCatogries();
            wrapPanel_SearchDetails.Visibility = System.Windows.Visibility.Visible;
            wrapPanel_UpdateCatName.Visibility = System.Windows.Visibility.Visible;

            button_catUpdate.Visibility = System.Windows.Visibility.Visible;
            button_catDelete.Visibility = System.Windows.Visibility.Visible;


            wrapPanel_EnterNewCat.Visibility = System.Windows.Visibility.Hidden;
            //wrapPanel_EnterCatRef.Visibility = System.Windows.Visibility.Hidden;

            button_catgryInsert.Visibility = System.Windows.Visibility.Hidden;
        }

        private void button_catUpdate_Click(object sender, RoutedEventArgs e)
        {


            objCat.Cat_reference = CatgoryAutocompleteTextBox.SelectedItem.ToString();
            objCat.Cat_name = textBox_EnterCatName.Text;

            ObjProjFunc.UpdateProjCatgries(objCat);


        }

        private void button_catUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                objCat.Cat_reference = label_CatRef.Content.ToString();
                objCat.Cat_name = textBox_EnterCatName.Text;

                ObjProjFunc.UpdateProjCatgries(objCat);
                MessageBox.Show("Catogry Name Updated Successfilly!!", "Updated Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            catch
            {
                MessageBox.Show("Updation Failed", "Updated Information", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        private void button_catDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Are You sure you want to Delete this Project Data", "Delete Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                bool isDeleted = false;

                Data_Categories clsCat = new Data_Categories();
                clsCat.Cat_reference = label_CatRef.Content.ToString();
                isDeleted = ObjProjFunc.DeleteProjects(clsCat);
                if (isDeleted == true)
                {

                    MessageBox.Show("Project Catogry Successfully", "CECB", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Project Catogry Failed", "CECB", MessageBoxButton.OK, MessageBoxImage.Warning);

                }
            }
        }
    }
}
